﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace zwWitLink
{
    public partial class Option : Form
    {
        Point mouseOff; bool canMove = false;
        public string server;
        public string fingerImgPath;
        public event EventHandler systemChanged;
        public Option()
        {
            InitializeComponent();
            this.Load += Option_Load;
        }

        void init() {
            tbDomain.Text = fingerImgPath;
            tbIP.Text = server;
        }
        void Option_Load(object sender, EventArgs e)
        {
            btnClose.MouseEnter += btnClose_MouseEnter;
            btnClose.MouseLeave += btnClose_MouseLeave;
            toolBar.MouseDown += toolBar_MouseDown;
            toolBar.MouseMove += toolBar_MouseMove;
            toolBar.MouseUp += toolBar_MouseUp;
            init();
        }
        void toolBar_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                canMove = false;
            }
        }

        void toolBar_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && canMove)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置  
                Location = mouseSet;
            }
        }

        void toolBar_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y);
                canMove = true;
            }
        }

        void btnClose_MouseLeave(object sender, EventArgs e)
        {
            btnClose.Image = Properties.Resources.closelight;
            //btnClose.BackColor = Color.FromArgb(255, 255, 255);
        }

        void btnClose_MouseEnter(object sender, EventArgs e)
        {
            btnClose.Image = Properties.Resources.close;
            //btnClose.BackColor = Color.FromArgb(251, 97, 85);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSet_Click(object sender, EventArgs e)
        {
            string Current = System.IO.Directory.GetCurrentDirectory();
            string path = Current + "/Config/config.ini";
            OcmKeep.IniHelper ini = new OcmKeep.IniHelper(path);
            if (tbIP.Text.Length == 0)
            {
                optionTip.Show("不能为空!", tbIP, 1000);
                return;
            }
            if (tbIP.Text.IndexOf("/") > 0||tbIP.Text.IndexOf(":") > 0) {
                optionTip.Show("格式错误 不能含有: /符号", tbIP, 1000);
                return;
            }
            if (DialogResult.Yes == MessageBox.Show("确定要修改吗？", "操作提醒", MessageBoxButtons.YesNo))
            {
                server = tbIP.Text;
                ini.WriteValue("Setting", "server", tbIP.Text);
                systemChanged(this, e);
               //ini.WriteValue("Setting", "fingerImgPath",tbDomain.Text);
               this.Close();
            }
            else
            {

            }
            
        }

        private void btnDomain_Click(object sender, EventArgs e)
        {
            folderDialog.ShowDialog();
            tbDomain.Text = folderDialog.SelectedPath;
        }
    }
}
